package com.sghd.candy.module.account.event;

import com.sghd.candy.module.account.manager.Account;
import com.sghd.candy.module.account.service.AccountService;
import com.sghd.candy.module.common.event.LogoutEvent;
import com.sghd.candy.module.player.manager.Player;
import com.sghd.candy.module.player.service.PlayerService;
import com.sghd.common.event.AbstractReceiver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 账号登出事件处理器
 * 
 */
@Component
public class LogoutEventReceiver extends AbstractReceiver<LogoutEvent> {
	@Autowired
	private AccountService accountService;
	@Autowired
	private PlayerService playerService;

	@Override
	public String[] getEventNames() {
		return new String[] { LogoutEvent.NAME };
	}

	@Override
	public void doEvent(LogoutEvent event) {
		// 登出
		long accountId = event.getOwner();
		Account account = this.accountService.load(accountId);
		final Player player = this.playerService.load(accountId);
		accountService.logout(account, player);
	}
}